package login.ui;

import java.awt.Color;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 * This is the panel used for the register screen. It contains all of the
 * components and UI elements necessary for a user to register a new user name &
 * password to login to the system.
 * 
 * @author Jiminikiz
 */

public class RegisterUI extends JPanel
{

  private static final long serialVersionUID = -480961696618582138L;

  private JLabel fNameLabel = new JLabel("First Name:");
  private JLabel lNameLabel = new JLabel("Last Name:");
  private JLabel sportLabel = new JLabel("Sport:");
  private JLabel roleLabel = new JLabel("Role:");
  private JLabel userLabel = new JLabel("User name:");
  private JLabel passLabel = new JLabel("New Password:");

  public JTextField usernameField = new JTextField(10);
  public JTextField passwordField = new JPasswordField(15);
  public JTextField fNameField = new JTextField(10);
  public JTextField lNameField = new JTextField(10);

  private String[] sports =
  { "Baseball", "Basketball", "Football", "Soccer" };
  private String[] roles =
  { "Admin", "Coach", "Athlete", "Fan" };

  public JComboBox sportsList = new JComboBox(sports);
  public JComboBox rolesList = new JComboBox(roles);

  private JButton submitButton = new JButton("Submit");
  private JButton cancelButton = new JButton("Cancel");

  // ButtonBar maker will have an array of buttons. In the following case,
  // Submit is @ 0, Cancel is @ 1, etc.
  // private ButtonBarMaker LoginBar = new ButtonBarMaker( "Submit", "Cancel"
  // );
  // private Box buttons = LoginBar.getButtons();

  // private final Dimension panelSize = new Dimension(200, 100);

  public RegisterUI()
  {
    super();
    
    this.setFocusable(true);
    
    setLayout(null);
    setOpaque(false);
    setLabelsStyles(fNameLabel, lNameLabel, sportLabel, roleLabel, userLabel, passLabel);

    int x = 45;
    int y = 20;

    int xGap = 10;
    int yGap = 40;

    int width = 120;
    int height = 20;

    fNameLabel.setBounds(x, y + (yGap * 0), width, height);
    fNameField.setBounds(x + (xGap * 12), 20, width + 60, height);
    lNameLabel.setBounds(x, y + (yGap * 1), width, height);
    lNameField.setBounds(x + (xGap * 12), 60, width + 60, height);

    sportLabel.setBounds(x, y + (yGap * 2), width, height);
    sportsList.setBounds(x + (xGap * 12), 100, width + 60, height);
    roleLabel.setBounds(x, y + (yGap * 3), width, height);
    rolesList.setBounds(x + (xGap * 12), 140, width + 60, height);

    userLabel.setBounds(x, y + (yGap * 4), width, height);
    usernameField.setBounds(x + (xGap * 12), 180, width + 60, height);
    passLabel.setBounds(x, y + (yGap * 5), width, height);
    passwordField.setBounds(x + (xGap * 12), 220, width + 60, height);

    submitButton.setBounds(90, 260, 100, 25);
    cancelButton.setBounds(210, 260, 100, 25);

    add(userLabel);
    add(usernameField);

    add(passLabel);
    add(passwordField);

    add(fNameLabel);
    add(fNameField);

    add(lNameLabel);
    add(lNameField);

    add(roleLabel);
    add(rolesList);

    add(sportLabel);
    add(sportsList);

    // JButton submit = LoginBar.getButton(0);

    add(submitButton);
    add(cancelButton);

    // add( buttons );
  }

  private void setLabelsStyles(JLabel... labels)
  {
    for (int i = 0; i < labels.length; i++)
    {
      labels[i].setForeground(Color.white);
      // labels[i].setHorizontalTextPosition(JLabel.RIGHT);
    }

  }

  public void addCancelAction(ActionListener actionListener)
  {
    cancelButton.addActionListener(actionListener);

  }

  public void addSubmitAction(ActionListener actionListener)
  {
    submitButton.addActionListener(actionListener);
  }

}